package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseAttrInfo;
import com.atguigu.gmall.model.product.BaseAttrValue;
import com.atguigu.gmall.product.service.BaseAttrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class BaseAttrController {

    @Autowired
    BaseAttrService baseAttrService;


    /**
     * 根据平台属性id,获取平台属性的所有值
     * @param attrId
     * @return
     */
    @GetMapping("getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable("attrId") Long attrId){
        List<BaseAttrValue> values = baseAttrService.getAttrValueList(attrId);
        return Result.ok(values);

    }


    /**
     * 保存属性信息(包含属性的值)
     * 添加修改二合一
     * @param baseAttrInfo
     * @return
     */
    @PostMapping("/saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        baseAttrService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }


    /**
     * 根据分类id,查出分类对应的所有平台属性
     * @param category1Id
     * @param category2Id
     * @param category3Id
     * @return
     */
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result getAttrInfoList(@PathVariable("category1Id")Long category1Id,
                                    @PathVariable("category2Id")Long category2Id,
                                    @PathVariable("category3Id")Long category3Id){

        //要查出平台属性的名和值
        List<BaseAttrInfo> attrInfos = baseAttrService.getAttrInfoListByCategoryId(category1Id,category2Id,category3Id);
        return Result.ok(attrInfos);

    }
}
